﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DCTLib.Common;
using System.Data;

namespace DCTAccess.Business.News
{
    public class NewsFilter
    {
        private int _productID = -1;
        private string _title = string.Empty;
        private string _images = string.Empty;
        private int _unitPrice = -1;
        private string _chuyenmuc = string.Empty;
        private string _nhucau = string.Empty;
        private string _chungloai = string.Empty;
        private string _noirao = string.Empty;
        private string _quanhuyen = string.Empty;
        private string _noidung = string.Empty;
        private int _createBy = -1;

        public int CreateBy
        {
            get { return _createBy; }
            set { _createBy = value; }
        }

        #region Property
        public int ProductID
        {
            get { return _productID; }
            set { _productID = value; }
        }
        
        public string Title
        {
            get { return _title; }
            set { _title = value; }
        }
        

        public string Images
        {
            get { return _images; }
            set { _images = value; }
        }
        

        public int UnitPrice
        {
            get { return _unitPrice; }
            set { _unitPrice = value; }
        }
        
        public string Chuyenmuc
        {
            get { return _chuyenmuc; }
            set { _chuyenmuc = value; }
        }
        

        public string Nhucau
        {
            get { return _nhucau; }
            set { _nhucau = value; }
        }
       

        public string Chungloai
        {
            get { return _chungloai; }
            set { _chungloai = value; }
        }
        

        public string Noirao
        {
            get { return _noirao; }
            set { _noirao = value; }
        }
        

        public string Quanhuyen
        {
            get { return _quanhuyen; }
            set { _quanhuyen = value; }
        }
        

        public string Noidung
        {
            get { return _noidung; }
            set { _noidung = value; }
        }
        #endregion

        private string SelectAllSQL
        {
            get
            {
                StringBuilder sql = new StringBuilder();
                sql.Append("select  pr.*, fp.FunctionPageName, n.NeedsName  from Product pr ");
                sql.Append(" inner join Needs n on n.NeedsID = pr.NeedsID ");
                sql.Append(" inner join FunctionPage fp on pr.CategoryPageID =  fp.FunctionPageID ");
                //sql.Append(" inner join FunctionPage fp on pr.CategoryPageID =  fp.FunctionPageID ");
                sql.Append("WHERE 1=1 ");

                return sql.ToString();
            }
        }

        public DataTable GetNews()
        {
            SQLHelper sqlHelper = new SQLHelper();
            sqlHelper.SwitchCommandType(CommandType.Text);

            StringBuilder sql = new StringBuilder(SelectAllSQL);

            if (ProductID != -1)
            {
                sql.Append("AND " + IntegerCompareSQLBuilder.GetSQL("ProductID", IntegerCompareTypes.Equals, "@ProductID"));
                sqlHelper.AddParameter("@ProductID", ProductID);
            }

            if (CreateBy != -1)
            {
                sql.Append("AND " + IntegerCompareSQLBuilder.GetSQL("CreateBy", IntegerCompareTypes.Equals, "@CreateBy"));
                sqlHelper.AddParameter("@CreateBy", CreateBy);
            }

            return sqlHelper.GetDataTable(sql.ToString() + " ORDER BY pr.ProductID DESC  ");
        }

    }
}
